package com.itmk.web.dashboard.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itmk.utils.ResultUtils;
import com.itmk.utils.ResultVo;
import com.itmk.web.dashboard.entity.TotalVo;
import com.itmk.web.goods.service.GoodsService;
import com.itmk.web.goods_category.entity.GoodsCategory;
import com.itmk.web.goods_category.service.GoodsCategoryService;
import com.itmk.web.order.service.OrderService;
import com.itmk.web.reports.entity.Reports;
import com.itmk.web.reports.service.ReportService;
import com.itmk.web.user.entity.User;
import com.itmk.web.user.service.UserService;
import com.itmk.web.user_auth.entity.UserAuth;
import com.itmk.web.user_auth.server.UserAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RequestMapping("api/dashboard")
@RestController
public class DashboardController {

    @Autowired
    private ReportService reportService;
    @Autowired
    private UserService userService;
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private GoodsCategoryService goodsCategoryService;

    @GetMapping("/getTotal")
    public ResultVo getTotal() {
        TotalVo vo = new TotalVo();
//        查询待处理投诉总数
        QueryWrapper<Reports> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(Reports::getStatus, 0);
        int handleRepTotal = reportService.count(queryWrapper);
        vo.setHandleRepTotal(handleRepTotal);
//        查询待审核认证总数
        QueryWrapper<User> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.lambda().eq(User::getStatus, 0);
        int handleAuthTotal = userService.count(queryWrapper1);
        vo.setHandleAuthTotal(handleAuthTotal);
//        查询用户总数
        int usersTotal = userService.count();
        vo.setUsersTotal(usersTotal);
//          查询闲置总数
        int goodsTotal = goodsService.count();
        vo.setGoodsTotal(goodsTotal);
//          查询订单总数
        int orderTotal = orderService.count();
        vo.setOrderTotal(orderTotal);

        return ResultUtils.success("get success", vo);


    }

    // DashboardController.java 添加新方法
    @GetMapping("/getCategoryGoodsCount")
    public ResultVo getCategoryGoodsCount() {
        List<GoodsCategory> list = goodsCategoryService.getCategoryGoodsCount();
        return ResultUtils.success("查询成功", list);
    }


    @GetMapping("/getOrderTrend")
    public ResultVo getOrderTrend() {
        List<Map<String, Object>> list = orderService.getOrderCountLast7Days();
        return ResultUtils.success("查询成功", list);
    }

}
